<template>
    <div>
        <h2>等级列表</h2>
        <table class="table table-bordered">
            用户名： <input type="text" v-model="state.rname" />
            <input type="button" value="查询" @click="getlist" />
            <tr>
                <th>等级名称</th>
                <th>最大值</th>
                <th>最小值</th>
                <th>折扣</th>
                <th>添加时间</th>
                <th>操作</th>
            </tr>
            <tr v-for="item in list">
                <td>{{ item.rightsName }}</td>
                <td>{{ item.max }}</td>
                <td>{{ item.min }}</td>
                <td>{{ item.daZhe }}</td>
                <td>{{ item.createTime.substring(0,10) }}</td>
                <td>
                    <input type="button" value="分配权益" @click="quanyi" />
                </td>
            </tr>
        </table>
        <div>
            <span>总条数{{ totalcount }}</span>
            <span>总页数{{ totalpage }}</span>
            <span>当前第{{ state.index }}/{{ totalpage }}</span>
            <input type="button" value="首页" @click="page('1')" />
            <input type="button" value="上一页" @click="page('2')" />
            <input type="button" value="下一页" @click="page('3')" />
            <input type="button" value="尾页" @click="page('4')" />
        </div>
    </div>
</template>

<script setup lang="ts">
import { onMounted, reactive, toRefs } from 'vue';
import axios from 'axios';
import { useRouter, useRoute } from 'vue-router';
const router = useRouter();
let data: any = reactive({
    state: {
        rname: "",
        index: 1,
        size: 2
    },
    list: [],
    totalcount: 0,
    totalpage: 0
})
let { state, list, totalcount, totalpage } = toRefs(data)
onMounted(() => {
    getlist()
})
const getlist = () => {
    let obj = {
        rname: state.value.rname,
        index: state.value.index,
        size: state.value.size
    }
    axios({
        url: '/api/Member/GetRights',
        method: 'get',
        params: obj
    })
        .then(res => {
            console.log(res)
            list.value = res.data.data
            totalcount.value = res.data.totalcount
            totalpage.value = res.data.totalpage

        })
        .catch(err => {
            console.log(err)
        })
}

const page=(str:any)=>{
switch(str){
    case"1":
    if(state.value.index==1){
        alert("已经是首页了")
        return 
    }
    state.value.index=1;
    break;
    case"2":
    if(state.value.index==1){
        alert("已经是首页了")
        return 
    }
    state.value.index--;
    break;
    case"3":
    if(state.value.index==totalpage.value){
        alert("已经是尾页了")
        return 
    }
    state.value.index++;
    break;
    case"4":
    if(state.value.index==totalpage.value){
        alert("已经是尾页了")
        return 
    }
    state.value.index=totalpage.value;
    break;
}
getlist();
}
const quanyi=()=>{
    router.push("/Qadd")
}



</script>

<style scoped></style>